//
//  UIButton+Extension.swift
//  Weibo
//
//  Created by 明丽 on 16/1/17.
//  Copyright © 2016年 明丽. All rights reserved.
//

import UIKit
extension UIButton {
    convenience init(imageName: String?,backImageName: String?) {
        self.init()
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
            setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
        }
        
        if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
        
        
        //指定大小
        sizeToFit()
    }
    
    convenience init(title: String, fontSize: CGFloat,color: UIColor,backImageName: String?,imageName: String? = nil) {
        self.init()
        //设置按钮的文字
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            
        }
    if imageName != nil {
    setImage(UIImage(named: imageName!), forState: .Normal)
    }
        sizeToFit()

    }
}
